package com.baymax.test.scene

import android.content.ComponentCallbacks
import android.content.res.Configuration
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.lifecycle.SavedStateViewModelFactory
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.airbnb.mvrx.MavericksView
import com.airbnb.mvrx.MavericksViewInternalViewModel
import com.baymax.test.scene.life.LifeLogger
import com.bytedance.scene.group.GroupScene
import com.bytedance.scene.ktx.requireNavigationScene
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.CoroutineContext

abstract class BaseGroupScene : GroupScene(), ComponentCallbacks,
    CoroutineScope  , MavericksView {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        lifecycle.addObserver(LifeLogger)
    }

    companion object {
        const val TAG = "BaseScene_Debug"
    }


    override fun onLowMemory() {

    }

    override fun onConfigurationChanged(newConfig: Configuration) {
    }



    override val mavericksViewInternalViewModel: MavericksViewInternalViewModel
        get() = ViewModelProvider(
            requireNavigationScene(),
            SavedStateViewModelFactory(
                requireNavigationScene().requireActivity().application,
                owner = (requireActivity() as ComponentActivity),
                defaultArgs = this.arguments
            )
        ).get(
            MavericksViewInternalViewModel::class.java
        )

    override fun invalidate() {

    }
    override val coroutineContext: CoroutineContext = lifecycleScope.coroutineContext
}